package org.example.springboot_gradle.service.impl;

import org.example.springboot_gradle.entity.Hostel;
import org.example.springboot_gradle.mapper.HostelMapper;
import org.example.springboot_gradle.service.IHostelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 宿舍表 服务实现类
 * </p>
 *
 * @author HAJ.it
 * @since 2025-02-18
 */
@Service
public class HostelServiceImpl extends ServiceImpl<HostelMapper, Hostel> implements IHostelService {

    @Autowired
    public HostelMapper hostelMapper;

    /**
     * 添加宿舍
     * */
    @Override
    public boolean insert(Hostel hostel){
        try {
            hostelMapper.insert(hostel);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    /**
     * 查询宿舍
     * */
    @Override
    public List<Hostel> findAll(){
        return hostelMapper.selectList(null);
    }

    /**
     * 修改宿舍
     * */
    @Override
    public boolean update(Hostel hostel){
        try {
            hostelMapper.updateById(hostel);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    /**
     * 删除宿舍
     * */
    @Override
    public boolean delete(Integer id){
        try {
            hostelMapper.deleteById(id);
            return true;
        }catch (Exception e){
            return false;
        }
    }

}
